package com.study.spmongodb.book.wwj.char01;

/**
 * @author MI
 * @version 1.0
 * @date 2020/11/23 21:50
 */
public class TicketWindow extends Thread {
    //柜台名称
    private final String name;

    //最多受理50笔业务员
    private static final int MAX = 50;

    //使用 static 修饰 ,做到了多线程下共享资源的唯一性
    private static int index = 1;

    public TicketWindow(String name) {
        this.name = name;
    }

    @Override
    public void run() {
        while (index <= MAX) {
            System.out.println("柜台 " + name + " 当前的号码是 " + (index++));
        }
    }

    public static void main(String[] args) {
        final TicketWindow t1 = new TicketWindow("一号出号机");
        t1.start();

        final TicketWindow t2 = new TicketWindow("二号出号机");
        t2.start();

        final TicketWindow t3 = new TicketWindow("三号出号机");
        t3.start();

        final TicketWindow t4 = new TicketWindow("四号出号机");
        t4.start();
    }
}
